class User < ActiveRecord::Base
  has_one :person, :through => :user_person
  has_many :user_roles
  has_many :roles, :through => :user_roles
  has_many :user_permissions
  has_many :permissions, :through => :user_permissions

  acts_as_authentic do |c|
    c.logged_in_timeout = 15.minutes
  end

  def has_role?(role_sym)
    roles.any? { |r| r.name.underscore.to_sym == role_sym }
  end

  def deliver_password_reset_instructions!
    reset_perishable_token!
    Notifier.deliver_password_reset_instructions(self)
  end

end
